package com.t216.dm216.intercoptor;

import com.t216.dm216.common.RedisUtil;
import com.t216.dm216.common.UserMap;
import com.t216.dm216.pojo.dto.DmUserDTO;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TokenInterceptor extends HandlerInterceptorAdapter {
    @Resource
    private RedisUtil redisUtil;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        if(token != null && token.length() > 0) {
            DmUserDTO userDTO =  redisUtil.get(token);
            System.out.println(userDTO);
            UserMap.set(userDTO);
        }
        return true;
    }
}
